import 'package:json_annotation/json_annotation.dart';

part 'feed.g.dart';

/// 运行命令生成g.dart文件
/// flutter packages pub run build_runner build
@JsonSerializable()
class Feed {
  // 返回数据长度
  @JsonKey(name: 'counts')
  int counts;
  // 是否为历史数据
  @JsonKey(name: 'is_history')
  bool isHistory;
  // 消息
  @JsonKey(name: 'message')
  String message;
  // 是否有更多
  @JsonKey(name: 'more')
  bool more;
  // 结果
  @JsonKey(name: 'result')
  String result;
  // 详细数据
  @JsonKey(name: 'feedList')
  List<FeedItem> feedList;

  Feed(this.counts, this.isHistory, this.message, this.more, this.result,
      this.feedList);

  factory Feed.fromJson(Map<String, dynamic> json) => _$FeedFromJson(json);

  Map<String, dynamic> toJson() => _$FeedToJson(this);
}

@JsonSerializable()
class FeedItem {
  // 用户翻页
  @JsonKey(name: 'post_id')
  int postId;
  // 类型
  @JsonKey(name: 'type')
  String type;
  // 网页链接
  @JsonKey(name: 'url')
  String url;
  // 发表日期
  @JsonKey(name: '发表日期')
  String publishedAt;
  // 作者 ID
  @JsonKey(name: 'site_id')
  String siteId;
  // 作者 ID
  @JsonKey(name: 'author_id')
  String authorId;
  // 摘要
  @JsonKey(name: 'excerpt')
  String excerpt;
  // 喜欢数
  @JsonKey(name: 'favorites')
  int favorites;
  // 评论数
  @JsonKey(name: 'comments')
  int comments;
  // 是否删除
  @JsonKey(name: 'delete')
  bool delete;
  // 是否更新
  @JsonKey(name: 'update')
  bool update;
  // 内容
  @JsonKey(name: 'content')
  String content;
  // 标题
  @JsonKey(name: 'title')
  String title;
  // 图片数量
  @JsonKey(name: 'image_count')
  int imageCount;
  // 图片组
  @JsonKey(name: 'images')
  List<ImageDetail> images;
  // 图片标签
  @JsonKey(name: 'tags')
  List<String> tags;
  // 时间标签
  @JsonKey(name: 'event_tags')
  List<String> eventTags;
  // 数据类型
  @JsonKey(name: 'data_type')
  String dataType;
  // 创建日期
  @JsonKey(name: 'created_at')
  String createAt;
  // 作者信息
  @JsonKey(name: 'site')
  Site site;
  @JsonKey(name: 'sites')
  List<String> sites;
  @JsonKey(name: 'recom_type')
  String recomTpye;
  @JsonKey(name: 'rqt_id')
  String rqtId;
  // 是否喜欢
  @JsonKey(name: 'is_favorite')
  bool isFavorite;

  FeedItem(
      this.postId,
      this.type,
      this.url,
      this.publishedAt,
      this.siteId,
      this.authorId,
      this.excerpt,
      this.favorites,
      this.comments,
      this.delete,
      this.update,
      this.content,
      this.title,
      this.site,
      this.images,
      this.tags,
      this.eventTags,
      this.sites,
      this.dataType,
      this.createAt,
      this.imageCount,
      this.recomTpye,
      this.rqtId,
      this.isFavorite);

  factory FeedItem.fromJson(Map<String, dynamic> json) =>
      _$FeedItemFromJson(json);

  Map<String, dynamic> toJson() => _$FeedItemToJson(this);
}

@JsonSerializable()
class ImageDetail {
  // 图片 ID
  @JsonKey(name: 'img_id')
  int imgId;
  // 用户 ID
  @JsonKey(name: 'user_id')
  int userId;
  // 题目
  @JsonKey(name: 'title')
  String title;
  // 摘要
  @JsonKey(name: 'excerpt')
  String excerpt;
  // 图片宽度
  @JsonKey(name: 'width')
  int width;
  // 图片高度
  @JsonKey(name: 'height')
  int height;
  // 图片描述
  @JsonKey(name: 'description')
  String description;

  ImageDetail(this.imgId, this.userId, this.title, this.excerpt, this.width,
      this.height, this.description);

  factory ImageDetail.fromJson(Map<String, dynamic> json) =>
      _$ImageFromJson(json);

  Map<String, dynamic> toJson() => _$ImageToJson(this);
}

@JsonSerializable()
class Site {
  // 作者 ID
  @JsonKey(name: 'siteId')
  String siteId;
  // 作者类型
  @JsonKey(name: 'type')
  String type;
  // 作者名称
  @JsonKey(name: 'name')
  String name;
  // 地区
  @JsonKey(name: 'domain')
  String domain;
  // 作者描述
  @JsonKey(name: 'description')
  String description;
  // 关注人数
  @JsonKey(name: 'followers')
  int followers;
  // 主页地址
  @JsonKey(name: 'url')
  String url;
  // 头像
  @JsonKey(name: 'icon')
  String icon;
  // 是否认证
  @JsonKey(name: 'verified')
  bool verified;
  // 认证类型
  @JsonKey(name: 'verified_type')
  int verifiedType;
  @JsonKey(name: 'verified_reason')
  String verifiedReason;
  @JsonKey(name: 'verifications')
  int verifications;
  @JsonKey(name: 'verification_list')
  List<VerificationItem> verificationList;
  // 是否关注
  @JsonKey(name: 'is_following')
  bool isFollowing;

  Site(
      this.siteId,
      this.type,
      this.name,
      this.domain,
      this.description,
      this.followers,
      this.url,
      this.icon,
      this.verified,
      this.verifiedType,
      this.verifiedReason,
      this.verifications,
      this.isFollowing,
      this.verificationList);

  factory Site.fromJson(Map<String, dynamic> json) => _$SiteFromJson(json);

  Map<String, dynamic> toJson() => _$SiteToJson(this);
}

@JsonSerializable()
class VerificationItem {
  @JsonKey(name: 'verification_type')
  int verificationType;
  @JsonKey(name: 'verification_reason')
  String verificationReason;

  VerificationItem(this.verificationType, this.verificationReason);

  factory VerificationItem.fromJson(Map<String, dynamic> json) =>
      _$VerificationItemFromJson(json);

  Map<String, dynamic> toJson() => _$VerificationItemToJson(this);
}
